package com.example.controller;

import com.example.pojo.Coach;
import com.example.pojo.CoachComment;
import com.example.pojo.Member;
import com.example.service.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ViewController {
    @Autowired
    private CoachService coachService;

    @Autowired
    private PrivateCourseService privateCourseService;
    @Autowired
    private CoachCommentService coachCommentService;
    @Autowired
    private MemberService memberService;
   @Autowired
    private TeachService teachService;
    @RequestMapping("coach")
    public String CoachIndex(Model model){
        List<Coach> coaches = coachService.selectAllCoaches();
        model.addAttribute("allCoaches",coaches);
        model.addAttribute("imgUrl","/download?filePath=/home/GymSys/pictures/4230e7a4-ca87-4789-ade3-c2169e2bb3fe.jpg");
        return "CoachIndex";
    }

    @RequestMapping("privateCourse")
    public String Coach(Model model, @Param("cid") int cid, HttpSession session){
        model.addAttribute("coach",coachService.selectCoachById(cid));
        model.addAttribute("courses", privateCourseService.selectByCid(cid));
        Member member = (Member) session.getAttribute("user");
        model.addAttribute("member", member);
        return "privateCourse";
    }
    @RequestMapping("/setTeachTime")
    public String setTeachTime(Model model, String date,String time){
        System.out.println(date);
        System.out.println(time);
        return "privateCourse";
    }

    @RequestMapping("privateCourseComment")
    public String privateCourseComment(Model model, @Param("cid") int cid){
        List<CoachComment> comments = coachCommentService.selectCoachCommentByCid(cid);
        //给每条评论绑定用户
        for(CoachComment comment: comments){
            comment.setUser(memberService.selectByMemberAccount(comment.getUid()).get(0));
        }
        model.addAttribute("comments",comments);
        return "privateCourseComment";
    }

    @RequestMapping("coachAdmin")
    public String coachAdmin(Model model){
        return "coachManage";
    }

    @RequestMapping("WebLogin")
    public String WebLogin(){
        return "login";
    }

    @RequestMapping("main")
    public String main(){
        return "main";
    }

}
